package com.stu.reflection.factory;

public class ReflectionFactory1 {
  private ReflectionFactory1() {}
  // 解决工厂方法与实现类的耦合，但仍然与接口耦合
  public static IMessage getInstanceOfMessage(String classFullName) {
    try {
      return (IMessage)Class.forName(classFullName).getDeclaredConstructor().newInstance();
    } catch (Exception e) {
      e.printStackTrace();
      return null;
    }
  }
  public static IAnimal getInstanceOfAnimal(String classFullName) {
    try {
      return (IAnimal)Class.forName(classFullName).getDeclaredConstructor().newInstance();
    } catch (Exception e) {
      e.printStackTrace();
      return null;
    }
  }
}
